app.controller("feedbackController",function($scope, $controller ,$location, feedbackService){
    $controller('baseController',{$scope:$scope,baseService:feedbackService});

    $scope.editIsuse = function (id, val, msg) {
        var bool = true;
        if (msg) {
            bool = window.confirm(msg);
        }
        if (bool) {
            var queryJson = {
                entity: {
                    id: id,
                    isuse: val
                }
            };
            feedbackService.edit(queryJson).success(function (res) {
                $scope.resHandler(res, function (res) {
                    alert("修改成功");
                    $scope.findPage();
                })
            })
        }

    };
    $scope.editStatus = function (id, val, msg) {
        var bool = true;
        if (msg) {
            bool = window.confirm(msg);
        }
        if (bool) {
            var queryJson = {
                entity: {
                    id: id,
                    status: val
                }
            };
            feedbackService.edit(queryJson).success(function (res) {
                $scope.resHandler(res, function (res) {
                    alert("修改成功");
                    $scope.findPage();
                })
            })
        }

    };

    $scope.batchEditIsuse = function (val, msg) {
        var bool = true;
        if (msg) {
            bool = window.confirm(msg);
        }
        if (bool) {
            var queryJson = {
                entity: {
                    isuse: val
                },
                ids : $scope.ids
            };
            feedbackService.updateManyByIds(queryJson).success(function (res) {
                $scope.resHandler(res, function (res) {
                    alert("修改成功");
                    $('.js_checkbox').prop("checked", false);
                    $scope.findPage();
                })
            })
        }

    };
    $scope.batchEditStatus = function (val, msg) {
        var bool = true;
        if (msg) {
            bool = window.confirm(msg);
        }
        if (bool) {
            var queryJson = {
                entity: {
                    status: val
                },
                ids : $scope.ids
            };
            feedbackService.updateManyByIds(queryJson).success(function (res) {
                $scope.resHandler(res, function (res) {
                    alert("修改成功");
                    $('.js_checkbox').prop("checked", false);
                    $scope.findPage();
                })
            })
        }

    };

    $scope.edit = function(direct){
        var entity = $scope.entity;
        entity.content = CKEDITOR.instances.content.getData();
        if(!entity.title){
            alert("请输入标题");
            return;
        }
        if(!entity.categoryIdList || entity.categoryIdList.length === 0){
            alert("请选择分类");
            return;
        }
        if(!entity.content){
            alert("请输入内容");
            return;
        }
        chapterService.edit({entity:$scope.entity}).success(function (res) {
            $scope.resHandler(res, function (res) {
                if(direct !== undefined){
                    location.href = direct;
                }else {
                    location.reload();
                }
            })
        })
    };

    $scope.listInit = function () {
        $scope.findPage();
    };

});
